# encoding: utf-8
from flask_wtf import FlaskForm
from wtforms import StringField, BooleanField, PasswordField
from wtforms.validators import Email, required, Length, equal_to

class BaseForm(object):
    def getError(self):
        error = self.errors.popitem()[1][0]
        return error

class LoginForm(FlaskForm, BaseForm):
    email = StringField(validators=[required(message="请填写邮箱！"), Email(message="请填写合法邮箱！")])
    password = PasswordField(validators=[required(message="请填写密码！"), Length(min=6, max=10, message="密码长度需要在6～10位之间！")])
    remember = BooleanField()


class ModifyPwdForm(FlaskForm, BaseForm):
    oldPassword = PasswordField(validators=[required(message="请填写旧密码！")])
    newPassword = PasswordField(validators=[required(message="请填写新密码！"), Length(min=6, max=10, message="新密码长度需要在6～10位之间！")])
    confirmPassword = PasswordField(validators=[equal_to("newPassword", message="两次密码不一致！")])


class ResetMailForm(FlaskForm, BaseForm):
    email = StringField(validators=[required(message="请填写邮箱！"), Email(message="请填写合法邮箱！")])
    captcha = StringField(validators=[required(message="请填写验证码！"), Length(min=6, max=6, message="请填写6位验证码！")])

class MailCaptchaForm(FlaskForm, BaseForm):
    email = StringField(validators=[required(message="请填写邮箱！"), Email(message="请填写合法邮箱！")])

